package com.ruoyi.web.controller.galaxy;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.galaxy.service.IGalaxyProjectService;
import com.ruoyi.galaxy.service.IGalaxyUserService;
import com.ruoyi.galaxy.vo.project.GalaxyApiProjectDetailResponse;
import com.ruoyi.galaxy.vo.project.GalaxyApiProjectEventResponse;
import com.ruoyi.galaxy.vo.project.GalaxyApiProjectListResponse;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author yeoman
 * @date 2025/4/10 16:15
 * @description 银河票务商品
 */
@Controller
@RequestMapping("/galaxy/project")
public class GalaxyProjectController extends BaseController {

    private final String prefix = "galaxy/project";

    @Resource
    private IGalaxyProjectService galaxyProjectService;

    @Resource
    private IGalaxyUserService galaxyUserService;

    @RequiresPermissions("galaxy:project:view")
    @GetMapping()
    public String project()
    {
        return prefix + "/project";
    }

    @PostMapping("/list")
    @RequiresPermissions("galaxy:project:list")
    @ResponseBody
    public TableDataInfo list() {
        startPage();
        GalaxyApiProjectListResponse response = galaxyProjectService.selectProjectList();
        return getDataTable(response.getList(), response.getTotal());
    }

    @RequiresPermissions("galaxy:project:detail")
    @GetMapping("/detail/{projectToken}")
    public String detail(@PathVariable("projectToken") String projectToken, ModelMap mmap) {
        mmap.put("projectDetail", galaxyProjectService.selectProjectDetail(projectToken));
        mmap.put("userList", galaxyUserService.selectUserAll());
        return prefix + "/detail";
    }

    @PostMapping("/detail")
    @RequiresPermissions("galaxy:project:detail")
    @ResponseBody
    public GalaxyApiProjectDetailResponse detail(String projectToken) {
        return galaxyProjectService.selectProjectDetail(projectToken);
    }

    @GetMapping("/event/{eventToken}/{userId}")
    @RequiresPermissions("galaxy:project:event")
    @ResponseBody
    public GalaxyApiProjectEventResponse event(@PathVariable("eventToken") String eventToken, @PathVariable("userId") Long userId) {
        return galaxyProjectService.selectProjectEvent(eventToken, userId);
    }


}
